home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / perl5 / XML / XPath / Node / Attribute.pm next >
Encoding:
Perl POD Document  |  2001-11-05  |  2.1 KB  |  136 lines

  1. # $Id: Attribute.pm,v 1.9 2001/11/05 19:57:47 matt Exp $
  2.  
  3. package XML::XPath::Node::Attribute;
  4.  
  5. use strict;
  6. use vars qw/@ISA/;
  7.  
  8. @ISA = ('XML::XPath::Node');
  9.  
  10. package XML::XPath::Node::AttributeImpl;
  11.  
  12. use vars qw/@ISA/;
  13. @ISA = ('XML::XPath::NodeImpl', 'XML::XPath::Node::Attribute');
  14. use XML::XPath::Node ':node_keys';
  15.  
  16. sub new {
  17.     my $class = shift;
  18.     my ($key, $val, $prefix) = @_;
  19.     
  20.         my $pos = XML::XPath::Node->nextPos;
  21.         
  22.         my @vals;
  23.         @vals[node_global_pos, node_prefix, node_key, node_value] =
  24.                 ($pos, $prefix, $key, $val);
  25.     my $self = \@vals;
  26.         
  27.     bless $self, $class;
  28.     
  29. }
  30.  
  31. sub getNodeType { ATTRIBUTE_NODE }
  32.  
  33. sub isAttributeNode { 1; }
  34.  
  35. sub getName {
  36.     my $self = shift;
  37.     $self->[node_key];
  38. }
  39.  
  40. sub getLocalName {
  41.     my $self = shift;
  42.     my $local = $self->[node_key];
  43.     $local =~ s/.*://;
  44.     return $local;
  45. }
  46.  
  47. sub getNodeValue {
  48.     my $self = shift;
  49.     $self->[node_value];
  50. }
  51.  
  52. sub getData {
  53.     shift->getNodeValue(@_);
  54. }
  55.  
  56. sub setNodeValue {
  57.     my $self = shift;
  58.     $self->[node_value] = shift;
  59. }
  60.  
  61. sub getPrefix {
  62.     my $self = shift;
  63.     $self->[node_prefix];
  64. }
  65.  
  66. sub string_value {
  67.     my $self = shift;
  68.     return $self->[node_value];
  69. }
  70.  
  71. sub toString {
  72.     my $self = shift;
  73.     my $string = ' ';
  74. #     if ($self->[node_prefix]) {
  75. #         $string .= $self->[node_prefix] . ':';
  76. #     }
  77.     $string .= join('',
  78.                     $self->[node_key],
  79.                     '="',
  80.                     XML::XPath::Node::XMLescape($self->[node_value], '"&><'),
  81.                     '"');
  82.     return $string;
  83. }
  84.  
  85. sub getNamespace {
  86.     my $self = shift;
  87.     my ($prefix) = @_;
  88.     $prefix ||= $self->getPrefix;
  89.     if (my $parent = $self->getParentNode) {
  90.         return $parent->getNamespace($prefix);
  91.     }
  92. }
  93.  
  94. 1;
  95. __END__
  96.  
  97. =head1 NAME
  98.  
  99. Attribute - a single attribute
  100.  
  101. =head1 API
  102.  
  103. =head2 new ( key, value, prefix )
  104.  
  105. Create a new attribute node.
  106.  
  107. =head2 getName
  108.  
  109. Returns the key for the attribute
  110.  
  111. =head2 getLocalName
  112.  
  113. As getName above, but without namespace information
  114.  
  115. =head2 getNodeValue / getData
  116.  
  117. Returns the value
  118.  
  119. =head2 setNodeValue
  120.  
  121. Sets the value of the attribute node.
  122.  
  123. =head2 getPrefix
  124.  
  125. Returns the prefix
  126.  
  127. =head2 getNamespace
  128.  
  129. Return the namespace.
  130.  
  131. =head2 toString
  132.  
  133. Generates key="value", encoded correctly.
  134.  
  135. =cut
  136.